package astoliarskyi.wicket.card;

import java.util.Calendar;
import astoliarskyi.wicket.card.restriction.RestrictionContainer;
import astoliarskyi.wicket.card.restriction.TripNumber;
import astoliarskyi.wicket.card.restriction.Term;
import java.math.BigDecimal;

public class Card {

	public enum CardType {
		PUPIL, STUDENT, STANDART;
	}

	private final int id;
	private final CardType cardType;
	protected final RestrictionContainer restrictionContainer;	

	protected Card(int id, CardType cardType, RestrictionContainer restriction) {
		this.id = id;
		this.cardType = cardType;
		this.restrictionContainer = restriction;

	}

	
	public boolean checkout(Calendar dateToday) {
		return restrictionContainer.checkout(dateToday);
		
	}
	
	public int getId() {
		return id;
	}

	public CardType getCardType() {
		return cardType;
	}

	public Term.TermType getTermType() {
		return restrictionContainer.getTermType();
	}

	public TripNumber.TripNumberType getTripNumberType() {
		return restrictionContainer.getTripNumberType();
	}

	public int getTripsLeft() {
		return restrictionContainer.getTripsLeft();
	}
	
	public void rechargeBy(BigDecimal rechargeAmount) {
		throw new UnsupportedForThisCardType();
	} 

	public Calendar getValidityTerm() {
		return restrictionContainer.getValidityTerm();
	}

	public BigDecimal getMoneyLeft() {
		throw new UnsupportedForThisCardType();
	}

	@Override
	public boolean equals(Object obj) {

		if (obj == null) return false;
		if (obj instanceof Card) {
			Card otherCard = (Card) obj;
			return this.getId() == otherCard.getId();
		} else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return id;	
	}

}
